package repo

import (
	"github.com/jinzhu/gorm"

	"github.com/pingcap-incubator/tidb-dashboard/pkg/model"
)

func ListRole(db *gorm.DB) ([]model.Role, error) {
	var roles []model.Role
	err := db.Raw("SELECT * FROM tidb_dashboard.role where status = 1 ").Scan(&roles).Error

	if err != nil {
		return nil, err
	}
	return roles, nil
}

func GetRole(db *gorm.DB, roleID uint) (*model.Role, error) {
	var role model.Role
	err := db.Table(RoleTable).Where("id = ? ", roleID).Scan(&role).Error
	if err != nil {
		return nil, ErrExecute.Wrap(err, "get role error")
	}
	return &role, nil
}
